package day20;

import java.io.File;

//delete a directory of context
//删除原理：从内往外删除，先删除目录下的所有文件，再删除目录
public class RemoveDir {

	public static void main(String[] args) {
		
	}
	
	//delete a directory
	public static void removeDir(File dir) {
		File[] files = dir.listFiles();
		//delete all files of a directory
		for (File file : files) {
			if (file.isDirectory()) {
				removeDir(file);
			} else {
				file.delete();
			}
		}
		//delete directory
		dir.deleteOnExit(); //dir.delete();
	}
}
